(function(){
    function GetCustomBalance(){
        this.init();
  
     
       
    }

    GetCustomBalance.prototype = {
        constructor:GetCustomBalance,
        init:function(){
            this.nodata = '<tr><td  colspan="8">暂无信息</td></tr>';
            var _this = this;
            $.datetimepicker.setLocale('ch');
            $('#endtime').datetimepicker({
                format: 'Y-m-d',
                value:new Date().dateadd("d", 1),
                maxDate: new Date(),
                onChangeDateTime:function(dp,$input){
                    var limitStart = new Date($('#begintime').val().replace('-','/'));
                    var nowStart = new Date($('#endtime').val().replace('-','/'));
                    if(limitStart > nowStart){
                        $('#endtime').val(limitStart.format("YY-M-D"))

                    }
                },
                timepicker: false
            });
            
            $('#begintime').datetimepicker({
                format: 'Y-m-d',
                value:new Date().dateadd("d", -1),
                maxDate: new Date(),
                onChangeDateTime:function(dp,$input){
                    var limitStart = new Date($('#endtime').val().replace('-','/'));
                    var nowStart = new Date($('#begintime').val().replace('-','/'));
                    if(limitStart < nowStart){
                        $('#begintime').val(limitStart.format("YY-M-D"))

                    }
                    
                },
                timepicker: false
            });
            
            this.getBalanceList(1);

            $("#searchBtn").unbind("click").click(function(){
                _this.getBalanceList(1);
           });
           $.extend({page:function(pn){
            _this.getBalanceList(pn);
          }});


        
        },
        getBalanceList:function( pn ){
            var _this = this;
            var cid = location.search.getParam("cuname");
            var type = $("#flowtype").val() ? "&type="+$("#flowtype").val() : "";
            var stime = "&stime="+$("#begintime").val() ;
            var etime = "&etime="+$("#endtime").val() ;

            var desc = $("#remarkbox").val() ? "&remark="+$("#remarkbox").val() : "";
            var searchName = $("#username").val() ? "&username="+$("#username").val() : "";
    
            $.ajax({
                type:"get",
                url:"/admin/change?username="+cid+type+desc+stime+etime+"&ps=20&pn="+pn,
                dataType:"json",
                success:function( info ){
                    var code = info.code;
                    var desc = info.desc;
                    if( code == 1 )
                    {
                        var data = info.data;
                        if( data.length )
                        {
                            var strArr = [];
                            var count = info.count;
                            var typejson = {
                                "100":"加款",
                                "101":"中奖",
                                "200":"减款",
                                "201":"投注",
                            };
                            data.forEach(function( value, key  ){
                                var uname = value.username;
                                var fid = value.fid;
                                var fmoney = parseFloat(value.money).toFixed(2);//流水金额
                                var balance = parseFloat(value.balance).toFixed(2);//新余额
                                var oldvalue = parseFloat(value.oldvalue).toFixed(2);//旧余额
                                var type = value.type;
                                var ctime = value.stime.substring(0,16);//添加时间
                                var desc = value.remark ;//备注

   
                                var html = '<tr><td>'+uname+'</td><td>'+fid+'</td>';
                                html += '<td>'+fmoney+'</td><td>'+balance+'</td><td>'+oldvalue+'</td><td>'+typejson[type]+'</td>';
                                html += '<td>'+ctime+'</td><td>'+desc+'</td>';
                                // html += '<td   class="matchineoprate"><a  href="javascript:;"  class="machineRecharge"  data-sid="'+siteid+'"  data-money="'+sysmoney+'">机器充值</a><a  href="javascript:;"   class="machineReduce"   data-sid="'+siteid+'"  data-money="'+sysmoney+'">机器扣款</a><a   href="mflow.html?sid='+siteid+'"  target="_blank">流水明细</a></td>
                                
                                html += '</tr>';
                                strArr.push(html);
                            });

                            $("#customBalance").html( strArr.join(""));

                        

                    
                               // 分页
                               var pn = count.pn;
                               var tp = count.tp;
                               var tr = count.tr;
                               $("#countpages").html( tp );
                               $("#countnums").html( tr );
           
                               var pageHtml = getPages(pn,tp, "$.page");
   
                               $("#paginationSel").html(pageHtml);


                           
                          
                        }
                        else
                        {
                            $("#customBalance").html(_this.nodata);

                        }

                    }
                    else
                    {
                        $.alert(code,desc);
                    }


                }
            });


        },


      
    };





  new GetCustomBalance();

}());